'''
Created on Nov 25, 2010

@author: philip
'''
from tip_service import TipService, AddTipRequest
from django.utils import simplejson
from django.http import HttpResponse
from models import Tip
from django.template.loader import render_to_string

def add(request):
    r = request.REQUEST
    tip = TipService().addTip(AddTipRequest(r["community"], r["content"]))
    tipPanelContent = render_to_string("wires/tips_renderer.html",{"tip":tip})
    return HttpResponse(simplejson.dumps({"tip":tip,"html":tipPanelContent},default=Tip.toJSON),mimetype="application/json")